<!-- 财务分析 -->
<template>
  <div class="finance">
    <!-- 财务数据 -->
    <yn-com-comTitle name="财务数据"></yn-com-comTitle>
    <div class="table">
      <div class="tableTab">
        <span
          class="tableBtn"
          :class="{on:index==idx}"
          @click="rate(key,index)"
          v-show="key!='yhzbb'||isBank=='bank'"
          v-for="(val,key,index) in typeZB"
          :key="key"
        >{{val}}</span>
      </div>
      <div class="tableTab">
        <span
          class="tableBtn"
          :class="{on:index==timeIdx}"
          @click="time(key,index)"
          v-for="(val,key,index) in timeType"
          :key="key"
        >{{val}}</span>
      </div>
    </div>
    <yn-finance-cwsj
      :data="cwsj"
      :method="method"
      :type="type"
      :typeNR="typeZB[method]"
      :isBank="isBank"
    ></yn-finance-cwsj>

    <!-- 财务结构 -->
    <yn-com-comTitle name="财务结构" class="mt15"></yn-com-comTitle>
    <div class="table">
      <div class="tableTab cwjgTab">
        <span
          class="tableBtn"
          :class="{on:index==timeCwjgIdx}"
          @click="timeCwjg(key,index)"
          v-for="(val,key,index) in timeTypeCwjg"
          :key="key"
        >{{val}}</span>
      </div>
    </div>
    <yn-finance-cwjg :data="cwjg" :isBank="isBank"></yn-finance-cwjg>
  </div>
</template>

<script>
import { finance, stockType } from "../script/api";
const typeZB = {
  zyzb: "主要指标",
  mgzb: "每股指标",
  ceznl: "成长能力",
  ylnl: "盈利能力",
  xjll: "现金流量",
  caznl: "偿债能力",
  yynl: "运营能力",
  zcfzb: "资产负债表",
  lrb: "利润表",
  xjllb: "现金流量表",
  yhzbb: "银行指标表"
  // cwjg: "财务结构"
};
const timeType = () => {
  return { 1: "按报告期", 2: "按年度", 3: "按单季度" };
};
export default {
  data() {
    return {
      cwsj: [],
      cwjg: [],
      idx: 0,
      timeIdx: 0,
      typeZB: typeZB,
      timeType: timeType(),
      timeTypeCwjg: timeType(),
      method: "zyzb",
      type: 1,
      isBank: "",
      timeCwjgIdx: 0,
      timeCwjgType: 1
    };
  },
  components: {},
  computed: {},
  mounted() {
    this.stockData();
    this.getData();
    this.getDataCwjg();
  },
  methods: {
    async stockData() {
      const stock = await stockType();
      this.isBank = stock;
    },
    async getData() {
         console.log('this.cwsj==>')
      const res = await finance({
        type: this.type,
        method: this.method
      });
      this.cwsj = res.length > 8 ? res.slice(0, 8) : res;
     
    },
    async getDataCwjg() {
      const data = await finance({
        type: this.timeCwjgType,
        method: "cwjg"
      });
      this.cwjg = data.length > 5 ? data.slice(0, 5) : data;
    },
    rate(ops, index) {
        console.log(ops,index)
      this.timeType = timeType();
      if (ops == "xjll" || ops == "yynl" || ops == "zcfzb") {
        delete this.timeType[3];
      }
      this.method = ops;
      this.idx = index;

      this.type = 1;
      this.timeIdx = 0;
      this.getData();
    },
    time(ops, index) {
      this.type = ops;
      this.timeIdx = index;
      this.getData();
    },
    timeCwjg(ops, index) {
      this.timeCwjgType = ops;
      this.timeCwjgIdx = index;
      this.getDataCwjg();
    }
  }
};
</script>
<style lang='scss' scoped>
</style>